<?php
session_start();
$currPage = "manage";

$host="mysql-user.cse.msu.edu"; // Host name
$username="hewittry"; // Mysql username
$password="A39777266"; // Mysql password
$db_name="hewittry"; // Database name

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

if ($_SESSION['usertype'] != "admin")
{
	header("location:index.php");
}

include("inc_header.php"); ?>

	<div id="content">
		<h2><a href="#">Manager Controls</a></h2>
		<div class="clearfix">

			<ul>
				<li><a href="deleteUser.php">Manage Users</a></li>

			</ul>
		</div>
		
		<h3>Site Statistics</h3>
		
		<?php
			$query = "SELECT COUNT(NonAdmins_AllUsers_LogonID) AS dealerCnt FROM Dealer";
			$result = mysql_query($query);
			$row = mysql_fetch_assoc($result);
			echo "<strong>Number of Dealers:</strong> " . $row['dealerCnt'] . "<br />";
			
			$query = "SELECT COUNT(NonAdmins_AllUsers_LogonID) AS regularCnt FROM RegisteredUser";
			$result = mysql_query($query);
			$row = mysql_fetch_assoc($result);
			echo "<strong>Number of Regular Users:</strong> " . $row['regularCnt'] . "<br />";
			
			$query = "SELECT COUNT(VehicleForSaleID) AS announcementCnt FROM VehicleForSale WHERE timestamp > " . (time() - 259200);
			$result = mysql_query($query);
			$row = mysql_fetch_assoc($result);
			echo "<strong>Number of Announcements:</strong> " . $row['announcementCnt'] . "<br />";
			
			$query = "SELECT COUNT(b.VehicleForSale_VehicleForSaleID) as Total, a.Make, a.Model, a.VehicleYear, a.VehicleForSaleID FROM VehicleForSale AS a, Notification AS b WHERE b.VehicleForSale_VehicleForSaleID = a.VehicleForSaleID GROUP BY b.VehicleForSale_VehicleForSaleID ORDER BY Total LIMIT 3";
			$result = mysql_query($query) or die(mysql_error());
			$i = 1;
			echo "<br /><strong>Top 10 Car Announcements</strong><br />";
			while($row = mysql_fetch_assoc($result))
			{
				echo "$i) " . $row["Total"] . " - " . $row['Year']. ' '. $row['Make'] . ' ' . $row['Model'] . "<br />";
				$i++;
			}
		?>
		** the code for the top 10 isn't nearly right.
	</div>

<?php include("inc_footer.php"); ?>
